package com.cjack.frenchexcel.service;


import com.cjack.frenchexcel.dao.ImgTextExtractRuleDao;
import com.cjack.frenchexcel.model.ImgTextExtractRuleModel;
import com.cjack.frenchexcel.table.ImgTextExtractRuleTable;
import com.cjack.frenchexcel.util.ModelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ImgTextExtractRuleService {

    @Autowired
    private ImgTextExtractRuleDao dao;

    public List<ImgTextExtractRuleModel> list(){
        return ModelUtils.copyListModel( dao.findAll(), ImgTextExtractRuleModel.class);
    }

    public void save( ImgTextExtractRuleModel model){
        dao.save( ModelUtils.copySignModel( model, ImgTextExtractRuleTable.class));
    }

    public void del( String ids){
        List< ImgTextExtractRuleTable> tables = new ArrayList<>();
        String[] idArr = ids.split( ",");
        for( String id : idArr){
            ImgTextExtractRuleTable table = new ImgTextExtractRuleTable();
            table.setId( Long.valueOf( id));
            tables.add( table);
        }
        dao.deleteInBatch( tables);
    }

}
